﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 玩家外观
/// </summary>
public class PlayerAppearance : MonoBehaviour
{
    public Transform headRoot;//头部外观挂载节点
    public Transform bodyBoneRoot;//身体根骨节点

    private void Start()
    {
        AppearanceManager.Instance.NextHead();//暂时测试用
    }

    /// <summary>
    /// 替换外观部位
    /// </summary>
    /// <param name="newPart">新的外观部位</param>
    public void ReplaceAppearancePart(AppearancePart newPart)
    {
        switch (newPart.appearancePartType)
        {
            case AppearancePartType.Head:
                if (headRoot.childCount > 0)
                {
                    Destroy(headRoot.GetChild(0).gameObject);
                }
                newPart.Init();
                newPart.SetAsNewPart(headRoot, GetBodyBonesTransArray());
                break;
            case AppearancePartType.Body:
            default:
                break;
        }
    }

    /// <summary>
    /// 获取到身体根骨下面的所有子节点（包括根骨）
    /// </summary>
    private Transform[] GetBodyBonesTransArray()
    {
        return bodyBoneRoot.GetComponentsInChildren<Transform>();
    }
}
